package com.ftg.learn.chapter13;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 学习流
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/2/15 下午3:04
 */
public class LearnStream01 {

    public static void main(String[] args) {
        Employeer[] emps = new Employeer[7];

        emps[0] = new Employeer("张三", new BigDecimal("10000"), "男", 1);
        emps[1] = new Employeer("李四", new BigDecimal("12000"), "男", 1);
        emps[2] = new Employeer("王五", new BigDecimal("18000"), "男", 1);
        emps[3] = new Employeer("李二狗", new BigDecimal("18000"), "男", 1);
        emps[4] = new Employeer("王春花", new BigDecimal("18000"), "男", 1);
        emps[5] = new Employeer("史小丽", new BigDecimal("18000"), "男", 1);
        emps[6] = new Employeer("高启强", new BigDecimal("18000"), "男", 1);

        //最大
//        Arrays.stream(emps).limit(3).forEach(System.out::println);

        //跳过
//        Arrays.stream(emps).skip(1).forEach(System.out::println);
        LearnStream01 l = new LearnStream01();
        while (true) {
            Scanner scanner = new Scanner(System.in);

            System.out.println("请选择你要的操作  1 分页功能，2 为查询功能 3 退出");
            int n = scanner.nextInt();
            if(n == 3){
                break;
            }
            switch (n) {
                case 1:
                    while(true){
                        System.out.println("请您输入开始位置,如果n为100退出");
                        n = scanner.nextInt();
                        if (n == 100)
                            break;
                        System.out.println("你要查看的数据");
                        l.skipPage(emps, n);
                    }
                    break;
                case 2:
                    System.out.println("请输入查询关键字");
                    String name = scanner.next();
                    l.findByName(emps,name);
                    break;
            }
        }

    }

    /**
     * 分页模拟
     *
     * @param emps    数据数组
     * @param pageNum 1 2 3 4
     */
    public void skipPage(Employeer[] emps, int pageNum) {
        int begin = (pageNum - 1) * 4;
        skipPage(emps, begin, 4);
    }


    /**
     * 从哪里开始 begin 到哪里结束 maxsize
     *
     * @param emps    数组
     * @param begin   开始位置
     * @param maxsize 显示几个
     */
    public void skipPage(Employeer[] emps, int begin, int maxsize) {
//        begin = (begin - 1) * maxsize;
        Arrays.stream(emps).skip(begin).limit(maxsize).forEach(System.out::println);
    }

    public void findByName(Employeer[] emps, String name) {
//        begin = (begin - 1) * maxsize;
        Arrays.stream(emps).filter(x -> x.getName().contains(name)).forEach(System.out::println);
    }

}
